package work.sby.web;

import work.sby.pojo.Brand;
import work.sby.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectByBrandName")
public class SelectByBrandName extends HttpServlet {

    private  BrandService service = new BrandService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        处理乱码
        request.setCharacterEncoding("utf-8");
        //1. 接收id
        String brandname = request.getParameter("brandname");

        //2. 调用service查询
        List<Brand> brands = service.selectByBrandName(brandname);
        //3. 存储到request中

        request.setAttribute("brands",brands);

        System.out.println("接收到的品牌名称：" + brandname); // 添加日志

        //4. 转发到update.jsp
        request.getRequestDispatcher("/select.jsp").forward(request,response);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
